'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-04-09 19:12:02
'''
# -*- coding: UTF-8 -*-

from tensorflow_train import TensorflowTrain
import sys
sys.path.append('../util')
from feature_handler import get_cate_fea_dict
import tensorflow as tf
import numpy as np
import time
import random

# 老板端特征
boss_base = ["boss_position", "boss_city", "boss_cmp_level", "boss_title_type", "boss_comp_scale"]
job_base = ["job_workyears", "job_degree", "jh", "jl"]
job_recent = ["job_det_times_7d", "job_det_times_2d", "job_addf_success_times_7d", "job_addf_times_7d", "job_addfchat_times_7d", "job_success_times_2d", "job_success_times_7d"]
boss_recent = ["boss_addfchat_times_2d", "boss_addf_times_2d", "boss_addf_success_times_2d", "boss_det_times_2d"]
boss_job_popular = ["boss_addf_pchat_times_2d", "job_plist_times_14d", "job_pdet_times_2d", "job_paddf_times_7d", "job_psuccess_times_7d", "job_pdet_times_14d", "boss_paddf_success_times_2d", "boss_pdet_times_2d", "job_paddf_times_14d", "job_pdet_times_7d", "boss_paddfchat_times_2d"]
boss_recent_base = ["b2g_workyears_recent10",  "b2g_gender_recent10", "b2g_apply_status_recent10", "b2g_cmp_level_recent10", "b2g_salary_recent10"]
boss_recent_school = ["b2g_school_level_recent10", "b2g_degree_recent10"]

# 牛人端特征
geek_base = ["geek_position", "geek_city", "geek_apply_status", "geek_gender", "eh", "el"]
geek_school = ["geek_degree_new", "geek_school_level", "geek_degree"]
geek_work = ["geek_major", "geek_rev_work_year", "geek_cmp_level", "geek_workyears"]
geek_recent = ["geek_det_times_7d", "geek_success_times_7d", "geek_success_times_2d", "geek_addfchat_times_2d", "geek_addfchat_times_7d", "geek_addf_times_7d"]
geek_exp_popular = ["geek_paddf_success_times_7d", "geek_plist_times_14d", "geek_pdet_times_2d", "geek_paddf_times_14d", "geek_paddf_times_7d", "geek_paddfchat_times_7d", "geek_paddf_times_2d", "geek_pdet_times_7d"]
geek_exp_reply = ["geek_paddf_pchat_times_7d", "geek_paddf_pchat_times_2d"]
geek_exp_active = ["geek_min_active_tdiff", "geek_min_chat_tdiff", "exp_register_tdiff", "exp_min_active_tdiff", "exp_det_num_24h", "geek_complete_tdiff"]

# 交叉特征
# cross_bias_recent = ["boss_view_geek_14d", "boss_det_geek_14d", "boss_pview_geek_14d", "boss_pdet_geek_14d"]
cross_bias_w2v = ["b2g_airbnb_emb_gof_int", "b2g_w2v_orig_gof", "b2g_w2v_pref_gof"]

all_fea_sum = boss_base+job_base+job_recent+geek_base+geek_school+geek_work+geek_recent+geek_exp_reply+geek_exp_popular+geek_exp_active+boss_recent_base+boss_recent_school+boss_job_popular+boss_recent+cross_bias_w2v

print(all_fea_sum)
f_path = "/data2/training_data/boss_rank/"
# f_path = "/data3/training_data/boss_rank_new/"
# f_path = "/data3/training_data/galaxy_data_new/"
dates = []
# dates.extend(["2020-03-" + str(i) for i in range(21, 32)])
# dates.extend(["2020-04-0" + str(i) for i in range(1, 10)])
# dates.extend(["2020-04-" + str(i) for i in range(10, 31)])
# dates.extend(['2020-05-0' + str(i) for i in range(1, 6)])
dates.append('2020-05-06')

#dates = ["2019-12-16", "2019-12-17", "2019-12-18", "2019-12-19", "2019-12-20", "2019-12-21", "2019-12-22", "2019-12-23", "2019-12-24", "2019-12-30", "2019-12-31", "2020-01-02", "2020-01-03", "2020-01-04", "2020-01-05", "2020-01-06", "2020-01-07", "2020-01-08", "2020-01-09", "2020-01-10"]
#dates = ["2020-01-12", "2020-01-13", "2020-01-14"]

fea_len_dict = {'boss_position': 216, 'boss_city': 216, 'boss_cmp_level': 200, 'boss_title_type': 192, 'boss_comp_scale': 200, 'job_workyears': 176, 'job_degree': 176, 'jh': 176, 'jl': 176, 'job_det_times_7d': 96, 'job_det_times_2d': 96, 'job_addf_success_times_7d': 96, 'job_addf_times_7d': 96, 'job_addfchat_times_7d': 96, 'job_success_times_2d': 96, 'job_success_times_7d': 96, 'geek_position': 256, 'geek_city': 256, 'geek_apply_status': 232, 'geek_gender': 226, 'eh': 240, 'el': 240, 'geek_degree_new': 152, 'geek_school_level': 152, 'geek_degree': 152, 'geek_major': 256, 'geek_rev_work_year': 240, 'geek_cmp_level': 240, 'geek_workyears': 240, 'geek_det_times_7d': 104, 'geek_success_times_7d': 104, 'geek_success_times_2d': 104, 'geek_addfchat_times_2d': 104, 'geek_addfchat_times_7d': 104, 'geek_addf_times_7d': 104, 'geek_paddf_pchat_times_7d': 72, 'geek_paddf_pchat_times_2d': 72, 'geek_paddf_success_times_7d': 216, 'geek_plist_times_14d': 216, 'geek_pdet_times_2d': 216, 'geek_paddf_times_14d': 216, 'geek_paddf_times_7d': 216, 'geek_paddfchat_times_7d': 216, 'geek_paddf_times_2d': 216, 'geek_pdet_times_7d': 216, 'geek_min_active_tdiff': 72, 'geek_min_chat_tdiff': 72, 'exp_register_tdiff': 72, 'exp_min_active_tdiff': 72, 'exp_det_num_24h': 72, 'geek_complete_tdiff': 72, 'b2g_workyears_recent10': 224, 'b2g_gender_recent10': 216, 'b2g_apply_status_recent10': 224, 'b2g_cmp_level_recent10': 224, 'b2g_salary_recent10': 224, 'b2g_school_level_recent10': 40, 'b2g_degree_recent10': 40, 'boss_addf_pchat_times_2d': 24, 'job_plist_times_14d': 24, 'job_pdet_times_2d': 24, 'job_paddf_times_7d': 24, 'job_psuccess_times_7d': 24, 'job_pdet_times_14d': 24, 'boss_paddf_success_times_2d': 24, 'boss_pdet_times_2d': 24, 'job_paddf_times_14d': 24, 'job_pdet_times_7d': 24, 'boss_paddfchat_times_2d': 24, 'boss_addfchat_times_2d': 64, 'boss_addf_times_2d': 64, 'boss_addf_success_times_2d': 64, 'boss_det_times_2d': 64, 'b2g_airbnb_emb_gof_int': 16, 'b2g_w2v_orig_gof': 16, 'b2g_w2v_pref_gof': 16}

#for k, v in fea_len_dict.items():
#    fea_len_dict[k] = 500

#第一次执行这一行要打开，生成特征需要length，替换fea_len_dict
# for fea in all_fea_sum:
#    fea_len_dict[fea] = 500

#类别特征取值字典
cate_fea_dict = get_cate_fea_dict()
conti_fea_cut = {"boss_pdet_geek_14d": [0, 1, 3, 5, 7, 10, 15, 20, 30], "job_paddf_times_14d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "job_pdet_times_14d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "job_plist_times_14d":[0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "boss_addf_pchat_times_2d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "geek_complete_tdiff": [-3972.5, -851.0, -396.5, -16.5, 0.0, 91.5, 400.0, 700.5, 1284.5, 3000, 6000, 12000, 24000, 40000, 52000, 62696.0, 85272.0, 317907.0, 318425.5, 653947.5, 942412.0, 942491.5, 957460.0, 2663842.5, 2664242.5, 2672580.0, 2841833.0, 2868163.0, 2868366.5, 2869354.5, 31965358.0, 110330768.0, 110337344.0], "geek_paddf_times_14d": [0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 11.0, 18.0, 28.0, 42.0, 60, 75, 90.0, 141.0, 147.0, 513.0, 567.5], "geek_plist_times_14d": [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], "geek_addfchat_times_2d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "job_addfchat_times_7d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], "geek_psuccess_times_7d": [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5],'el': [1.0, 3.0, 5.0, 7.0, 11.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 50.0, 65.0, 80.0, 100.0, 200.0], 'eh': [0.0, 6.0, 7.0, 11.0, 16.0, 18.0, 20.0, 22.0, 25.0, 30.0, 35.0, 40.0, 50.0, 65.0, 80.0, 100.0, 200.0], 'exp_min_active_tdiff': [1.0, 2.0, 56.0, 189.0, 788.0, 2059.0, 2062.0, 2066.0, 2115.0, 2135.0, 2269.0, 3500, 4700, 6000, 8000, 12000, 20000, 34000, 50000, 63830.0, 481756.0, 2523787.5, 5135030.0, 15550708.0], 'exp_det_num_24h': [0.0, 1.0, 4.0, 6.0, 14.0, 19.0, 26.0, 35, 50, 75, 100], 'exp_pas_addf_num_24h': [0.0, 1.0, 2.0, 3.0, 5.0, 7.0, 15.0, 30.0, 65.0, 143.0], 'g2b_position_addf_rate': [0.0, 0.002, 0.011, 0.014, 0.017, 0.018, 0.019, 0.021, 0.023, 0.024, 0.039, 0.041, 0.046, 0.048, 0.06, 0.08, 0.12, 0.2, 0.25], 'job_addf_rate_7d': [0.0, 0.002381, 0.017778, 0.027, 0.040816, 0.0589285, 0.058974, 0.085333, 0.0854095, 0.109099, 0.109244, 0.1102635, 0.128205, 0.156728, 0.157143, 0.210526, 0.2141895, 0.25407651, 0.25464901, 0.30333301, 0.383333, 0.466667, 0.4675515, 0.545614, 0.60817748, 0.78062749], 'b2g_work_distance': [0.0, 1, 3, 5, 7.46199989, 12, 16, 20, 30, 50, 75, 100, 123.069, 250, 400, 700, 1046.40796, 1046.92395, 1047.12854, 1048.30054, 1048.323, 1171.41797, 13046.8135, 13048.3389, 18184.543], 'job_addf_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_min_active_tdiff': [1.0, 2.0, 56.0, 189.0, 788.0, 2059.0, 2062.0, 2066.0, 2115.0, 2135.0, 2269.0, 3500, 4700, 6000, 8000, 12000, 20000, 34000, 50000, 63830.0, 481756.0, 2523787.5, 5135030.0, 15550708.0], 'geek_det_times_7d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'b2g_position_addf_rate': [0.0, 0.03, 0.054, 0.073, 0.087, 0.099, 0.117, 0.13, 0.145, 0.156, 0.168, 0.178, 0.18099999, 0.2, 0.23, 0.3, 0.4], 'geek_workdist_sensi': [-1.0, 0.85420001, 0.85610002, 0.85619998, 0.86119998, 0.8617, 5.09560013, 5.10445023, 5.10515022, 5.11520004, 8.86839962, 9.38934994, 9.9126997], 'jl': [0.0, 1.0, 2.0, 3.0, 4.0, 6.0, 10.0, 15.0, 17.0, 21.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 65.0, 80.0, 100.0, 200.0], 'exp_register_tdiff': [-3972.5, -851.0, -396.5, -16.5, 0.0, 91.5, 400.0, 700.5, 1284.5, 3000, 6000, 12000, 24000, 40000, 52000, 62696.0, 85272.0, 317907.0, 318425.5, 653947.5, 942412.0, 942491.5, 957460.0, 2663842.5, 2664242.5, 2672580.0, 2841833.0, 2868163.0, 2868366.5, 2869354.5, 31965358.0, 110330768.0, 110337344.0], 'jh': [4.0, 8.0, 11.0, 18.0, 20.0, 24.0, 30.0, 35.0, 40.0, 45.0, 50.0, 60.0, 70.0, 74.5, 75.0, 80.0, 100.0, 200.0], 'b2g_city_addf_rate': [0.0, 0.01, 0.011, 0.013, 0.0175, 0.022, 0.0225, 0.025, 0.04, 0.065, 0.1], 'job_addf_pchat_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'boss_pview_geek_14d': [1, 3, 5, 7, 10, 15, 20, 30], 'boss_view_geek_14d': [1, 3, 5, 7, 10, 15, 20, 30], 'job_success_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_det_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_success_times_7d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'geek_paddf_times_7d': [0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 11.0, 18.0, 28.0, 42.0, 60, 75, 90.0, 141.0, 147.0, 513.0, 567.5], 'geek_paddfchat_times_7d': [0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 11.0, 18.0, 28.0, 42.0, 60, 75, 90.0, 141.0, 147.0, 513.0, 567.5], 'geek_pdet_times_2d': [0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 11.0, 18.0, 28.0, 42.0, 60, 75, 90.0, 141.0, 147.0, 513.0, 567.5], 'geek_psuccess_rate_7d': [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.82876438, 0.88461536, 0.93333334, 0.97409326, 0.97419357, 0.98837209, 1.0], 'geek_paddf_pchat_times_7d': [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 11.0, 20, 35.0, 49.0, 52.0, 79.0, 80.0], 'geek_paddf_pchat_rate_7d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], 'geek_paddf_success_rate_7d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], "job_pdet_times_7d": [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_addfchat_times_7d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'boss_pdet_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_psuccess_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_addf_success_rate_7d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], 'job_paddfchat_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_addf_success_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_paddfchat_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_paddf_success_rate_2d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_paddf_success_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_psuccess_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_addf_rate_2d': [0.0, 0.002381, 0.017778, 0.027, 0.040816, 0.0589285, 0.058974, 0.085333, 0.0854095, 0.109099, 0.109244, 0.1102635, 0.128205, 0.156728, 0.157143, 0.210526, 0.2141895, 0.25407651, 0.25464901, 0.30333301, 0.383333, 0.466667, 0.4675515, 0.545614, 0.60817748, 0.78062749], 'boss_det_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_addfchat_rate_2d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'boss_addf_success_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_addf_success_rate_2d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], 'b2g_w2v_pref_gof': [-499.5409, 0.001, 0.5135, 0.6871, 0.728, 0.73, 0.7313, 0.8142, 0.8397, 0.8804, 0.8809, 0.9127, 0.9134, 0.9323, 0.9329, 99999999.0], 'b2g_airbnb_emb_gof_int': [-0.8001, -0.0403, -0.0028, -0.0011, 0.001, 0.0027, 0.1337, 0.5041, 0.5078, 0.513, 0.5513, 0.9386, 0.9566, 99999999.0], 'b2g_skill_match': [-499.5786, 0.104, 0.3838, 0.3886, 0.4113, 0.4502, 0.7048, 0.753, 0.7884, 0.7888, 0.912, 0.9124, 0.9661, 0.9973, 99999999.0], 'b2g_title_w2v_orig_gof': [-0.1308, -0.0065, 0.4567, 0.4588, 0.5733, 0.6836, 0.7184, 0.7208, 0.7304, 0.7309, 0.7405, 99999999.0], 'b2g_w2v_orig_gof': [-499.5621, 0.3535, 0.55, 0.551, 0.6555, 0.6934, 0.6991, 0.7586, 0.7597, 0.7766, 0.798, 0.8459, 0.8999, 0.9433, 99999999.0], 'geek_min_chat_tdiff': [1.0, 2.0, 56.0, 189.0, 788.0, 2059.0, 2062.0, 2066.0, 2115.0, 2135.0, 2269.0, 3500, 4700, 6000, 8000, 12000, 20000, 34000, 50000, 63830.0, 481756.0, 2523787.5, 5135030.0, 15550708.0], 'b2g_pos_pastpos_similarity': [-0.5,0.0,0.011,0.0128,0.0129,0.0449,0.0626,0.0633,0.0648,0.0665,0.0795,0.0804,0.0853,0.0894,99999999.0], 'b2g_pos_similarity': [0.0001,0.0007,0.0008,0.0009,0.0109,0.011,0.0113,0.0128,0.0508,0.0513,0.0528,0.0581,0.0624,0.0851,99999999.0], 'boss_addfchat_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_det_geek_14d': [1, 3, 5, 7, 10, 15, 20, 30], 'boss_paddf_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_pdet_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_det_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_addfchat_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'boss_psuccess_rate_2d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_success_rate_7d': [0.0, 0.002381, 0.017778, 0.027, 0.040816, 0.0589285, 0.058974, 0.085333, 0.0854095, 0.109099, 0.109244, 0.1102635, 0.128205, 0.156728, 0.157143, 0.210526, 0.2141895, 0.25407651, 0.25464901, 0.30333301, 0.383333, 0.466667, 0.4675515, 0.545614, 0.60817748, 0.78062749], 'job_success_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_addf_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'boss_paddfchat_rate_2d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'boss_paddf_rate_2d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_pdet_rate_14d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'job_paddf_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'boss_paddf_success_times_2d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_success_times_2d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'geek_success_rate_7d': [0.0, 0.00561, 0.01, 0.025559, 0.03125, 0.061224, 0.085, 0.1, 0.123231, 0.123693, 0.125, 0.12568299, 0.133333, 0.18, 0.25, 1.0], 'geek_paddf_success_times_7d': [0.0, 1.0, 2.0, 3.0, 5.0, 8.0, 11.0, 18.0, 28.0, 42.0, 60, 75, 90.0, 141.0, 147.0, 513.0, 567.5], 'geek_paddf_rate_7d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], 'geek_paddf_pchat_rate_2d': [0.0, 0.027586, 0.027668, 0.052632, 0.1, 0.17, 0.25, 0.33333299, 0.5, 0.65, 0.8, 0.96153802, 1.0], 'b2g_major_w2v_gof': [-499.5668,0.1619,0.4941,0.495,0.5844,0.6496,0.6557,0.6649,0.6659,0.9251,0.9279,0.9291,99999999.0], 'job_paddfchat_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_addf_pchat_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'job_paddf_times_7d': [0.0, 1.0, 3.0, 5.0, 8, 13.0, 20.0, 31.0, 46.0, 50.0, 97.0, 100.0, 101.0, 145.0, 186.0, 199.0, 201.0, 475.0, 1112.0, 1197.5], 'geek_addf_times_7d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'geek_pdet_times_7d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'geek_paddf_times_2d': [0.0, 1.0, 3.0, 6, 10, 16, 24.0, 34, 50, 64, 81.0, 84.0, 357.5], 'geek_paddf_pchat_times_2d': [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 11.0, 20, 35.0, 49.0, 52.0, 79.0, 80.0]}


class DeepFMSuccess(TensorflowTrain):

    #def get_train_file(self, date):
    #    paths = []
     #   for i in range(10):
      #      paths.append(self.file_path + "merge_train_data/" + date + "/part" + str(i))
       # return paths
#    def get_train_file(self, date):
#        return [self.file_path + date + "/E1_1/out"]
#        return [self.file_path + "1"]

    def make_label(self, l):
        if l == 'success':
            return 1
#        if random.randint(1, 44) == 5:
#            return 0
#        return -99
        return 0
    def define_network(self):
        # FFM部分
        print("子类定义network")
        base_fm = [self.concat_fm(boss_base, geek_base, 16), self.concat_fm(job_base, geek_base, 16),
                   self.concat_fm(boss_base, geek_school, 8), self.concat_fm(boss_base, geek_work, 16),
                   self.concat_fm(job_base, geek_work, 16), self.concat_fm(boss_recent_base, geek_base, 16), self.concat_fm(boss_recent_base, geek_school, 16),
                   self.concat_fm(boss_recent_base, geek_work, 16), self.concat_fm(boss_recent_school, geek_school, 8),
                   self.concat_fm(job_recent, geek_recent, 8), self.concat_fm(boss_recent, geek_recent, 8), self.sum_pooling_fm(boss_job_popular, geek_exp_popular, 8),
                   self.sum_pooling_fm(job_recent, geek_exp_popular, 16), self.sum_pooling_fm(job_recent, geek_exp_reply, 8),
                   self.sum_pooling_fm(job_recent, geek_exp_active, 8)]

        # NN部分
        base_nn = [
                   self.get_nn_input(job_base + geek_work, [16, 16, 16, 16, 32, 16, 16, 16]), self.get_nn_input(boss_base,[32, 32, 16, 8, 16]),
                   self.get_nn_input(geek_base, [32, 32, 8, 2, 16, 16]), self.get_nn_input(geek_school, [16, 16, 16]),
                   self.get_nn_input(boss_recent_base, [16, 8, 16, 16, 16]), self.get_nn_input(boss_recent_school, 16),
                   self.get_nn_input(job_recent + geek_recent + geek_exp_popular + geek_exp_reply + geek_exp_active + boss_job_popular + boss_recent, 16),
                   self.get_nn_input(cross_bias_w2v, 16),
                   #self.get_nn_input(cross_bias_recent, 16)
                  ]

        fm_res = tf.add_n(base_fm)


        base_nn = tf.concat(base_nn, axis=1)

        nn_out = self.nn_tower(base_nn, [128, 32, 1], 'nn_tower_')

        nn_out += fm_res
        #nn_out  = fm_res
        self.predict = tf.sigmoid(tf.reshape(nn_out, shape=[-1, 1]), name='predict')

        self.label_ph = tf.placeholder(dtype=tf.float32, shape=(None,), name='label')
        self.loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=self.label_ph, logits=nn_out, name='loss')

        self.train_op = tf.train.AdagradOptimizer(0.01, name='optimizer').minimize(self.loss, name='train_op')



def get_deepfm_success_simple(file_path, f_dates, watch_num, batch_size, thread_num, read_data_parallel, name, variable_dir='', save_dir='', only_predict=False):
    return DeepFMSuccess(file_path, f_dates, watch_num, batch_size, thread_num, read_data_parallel, fea_len_dict, cate_fea_dict, conti_fea_cut, name, all_fea_sum, use_data_set=False, variable_dir=variable_dir, save_dir=save_dir, only_predict=only_predict)

if __name__ == '__main__':
    # deepfm_train = DeepFMSuccess(f_path, dates, 200000, 200, 24, 0, fea_len_dict, cate_fea_dict, conti_fea_cut, 'serv', all_fea_sum, use_data_set=False, variable_dir='', save_dir='/data1/xuejian/sync/offline_train/tensorflow/model/'+'tf_model/deepfm_success_0506', only_predict=False)
#    deepfm_train = DeepFMSuccess(f_path, dates, 100000, 200, 24, 0, fea_len_dict, cate_fea_dict, conti_fea_cut, 'deepFM', all_fea_sum, use_data_set=False, variable_dir='', save_dir='/data1/arc_six/wuxiushan/model/'+'tf_model/deepfm_success_0117', only_predict=False)

#    deepfm_train = DeepFMSuccess(f_path, dates, 400000, 4000, 20, 0, fea_len_dict, cate_fea_dict, conti_fea_cut, 'deepFM', all_fea_sum, use_data_set=False, variable_dir='/data1/wuxiushan/model/tf_model/deepfm_success_0718_recent2', only_predict=True)
    deepfm_train = DeepFMSuccess(f_path, dates, 10000, 100, 20, 0, fea_len_dict, cate_fea_dict, conti_fea_cut, 'deepFM', all_fea_sum, use_data_set=False, variable_dir='/data1/xuejian/sync/offline_train/tensorflow/model/tf_model/deepfm_success_0506', only_predict=True)
    before = time.time()
    deepfm_train.train()
    after = time.time()
    print("time = ", after - before)